#ifndef __KERNEL_TIMER_H__
#define __KERNEL_TIMER_H__

#define TIMER_FLAG_SINGLE  0x01
#define TIMER_FLAG_START   0x10
#define TIMER_FLAG_TIMEOUT 0x20

#define TIMER_CMD_SET_TIME 1

struct timer {
	struct object parent;
	struct list list;
	void (*timeout_func) (void *args);
	void *args;
	ubase_t init_tick;
	ubase_t timeout_tick;

	uint8_t flag;
};

/* 创建一个定时器 */
extern struct timer *timer_create(const char *name,
				  void (*timeout_func) (void *args),
				  void *args,
				  ubase_t time,
				  uint8_t flag);

/* 初始化定时器 */
extern err_t timer_init(struct timer *timer,
				  const char *name,
				  void (*timeout_func) (void *args),
				  void *args,
				  ubase_t time,
				  uint8_t flag);

/* 删除一个定时器 */
extern err_t timer_del(struct timer *timer);

/* 启动一个定时器 */
extern err_t timer_start(struct timer *timer);

/* 停止一个定时器 */
extern err_t timer_stop(struct timer *timer);

/* 定时器控制函数 */
extern err_t timer_control(struct timer *timer, uint8_t cmd, void *args);

/* 检查定时器是否超时 */
extern void timer_timeout_check(void);

#endif
